<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>主页</title>
</head>
<link href="./layui/css/layui.css" rel="stylesheet">

<body>
<div style="margin: 0 auto;width:70%;display: block">
<form class="layui-form" action="" >

    <div class="layui-form-item">
        <h1>我的信息</h1>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">题目</label>
        <div class="layui-input-block">
            <input type="text" name="title" required  placeholder="请输入内容"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">英文题目</label>
        <div class="layui-input-block">
            <input type="text" name="title_en" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学号</label>
        <div class="layui-input-block">
            <input type="text" name="stuid" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学生姓名</label>
        <div class="layui-input-block">
            <input type="text" name="stuname" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">英文姓名</label>
        <div class="layui-input-block">
            <input type="text" name="stuName_en" required  placeholder="请输入内容"
                   autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">学院</label>
        <div class="layui-input-block">
            <input type="text" name="college" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">中文关键字</label>
        <div class="layui-input-block">
            <input type="text" name="Keywords" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">英文关键字</label>
        <div class="layui-input-block">
            <input type="text" name="Keywords_en" required  placeholder="请输入内容"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学生专业</label>
        <div class="layui-input-block">
            <input type="text" name="stuMajor" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">老师姓名</label>
        <div class="layui-input-block">
            <input type="text" name="teaName" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">老师职称</label>
        <div class="layui-input-block">
            <input type="text" name="teaPro" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">中文摘要</label>
        <div class="layui-input-block">

            <textarea name="Abstract" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">英文摘要</label>
        <div class="layui-input-block">
            <textarea name="Abstract_en" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">参考文献</label>
        <div class="layui-input-block">
            <textarea name="Document" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>






    <div class="layui-form-item">
        <label class="layui-form-label">致谢</label>
        <div class="layui-input-block">
            <textarea name="Thanks" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
            <a href="./titleList.html" class="layui-btn layui-btn-primary">跳转到论文目录</a>
            <a href="./allTitle.html" class="layui-btn layui-btn-normal" target="_blank">查看整体标题</a>
            <a href="./putFile.php" class="layui-btn layui-btn-warm" target="_blank">下载源文件</a>
        </div>
    </div>

</div>
</form>
</body>

</html>
<script src="./js/jquery-1.9.1.min.js"></script>
<script src="./layui/layui.js"></script>
<script>
    var form_token = null;
    $(function () {
        getInfo();
    });
    function getInfo() {
        $.ajax({
            type: 'post',
            url: './info.php',
            success: function (data) {
                var jsonData = JSON.parse(data);
                console.log(jsonData)
                if (jsonData.status) {
                    layer.msg("进入成功")
                    form_token = jsonData.msg.form_token

                    for (msg_i in jsonData.msg.basic_info){
                        if (msg_i=="Document" || msg_i=="Thanks"|| msg_i=="Abstract"|| msg_i=="Abstract_en"){
                            jsonData.msg.basic_info[msg_i]=jsonData.msg.basic_info[msg_i].replace(/\\r\\n/g,"\n")
                        }
                        $('[name="'+msg_i+'"]').val(jsonData.msg.basic_info[msg_i])
                    }
                } else {
                    layer.msg(jsonData.msg)
                }
            },
            error: function () {
                layer.msg("请求异常")

            }
        });
    }

    layui.use('form', function(){
        var form = layui.form;
        //提交
        form.on('submit(formDemo)', function(data){
            console.log(data.field)
            data.field.form_token=form_token;
            data.field.Document=data.field.Document.replace(/\n|\r\n/g,'\\r\\n');
            data.field.Thanks=data.field.Thanks.replace(/\n|\r\n/g,'\\r\\n');
            data.field.Abstract=data.field.Abstract.replace(/\n|\r\n/g,'\\r\\n');
            data.field.Abstract_en=data.field.Abstract_en.replace(/\n|\r\n/g,'\\r\\n');
            $.ajax({
                type: 'post',
                url: './infoToDB.php',
                data:data.field,
                success: function (s_data) {
                    var s_data_obj = JSON.parse(s_data);
                    if (s_data_obj.status){
                        layer.msg(s_data_obj.msg)
                    }else {
                        layer.msg(s_data_obj.msg)
                    }
                },
                error: function () {
                    layer.msg("请求异常")
                }
            })
            return false;
        });
    });
</script>